<?php session_start(); ?>
<link rel="stylesheet" type="text/css" href="public/css/css-index.css">
<?php
require_once"libraries/utilites/functions.php";
$path = "data/films.txt";
$full_path = realpath($path);
$fimls = mreadFile($full_path);
?>
<!-- Phần đăng xuất -->
<?php if (isset($_GET["logout"])&& $_GET["logout"]==true) { ?>
    <?php unset($_SESSION["id"]); ?>
    <?php header("location:login.php"); ?>
<?php } ?>

<?php if (isset($_SESSION["id"])) { ?>
    <div id="khung">
        <form method="POST">
            <div id="search_rating">
 <div id="logout"><a href="index.php?logout=true">&nbsp;&nbsp; Logout </a></div>
                <input type="text" name="rating1" placeholder="rating 1">
                <input type="text" name="rating2" placeholder="rating 2">
                <input type="submit" name="submit" value="Search">
            </div>
        </form>
        <div id="ketqua">
            <div class="head-item">   
                <?php foreach ($fimls as $fiml): ?>
                    <?php $fiml = trim($fiml, "\t\n\r "); ?>
                    <?php $mang = explode(";", $fiml); ?> 
                    <?php if (!empty($fiml)) { ?>
                        <?php if (isset($_POST["rating1"])) { ?>
                            <?php if ($mang[3] >= (double) $_POST["rating1"] && $mang[3] <= (double) $_POST["rating2"]) { ?>
                                    <div class="item"<?php if(isset($_GET["id"])&&$_GET["id"]==$mang[0]) echo "id=edit"; ?>>
                                    <div class="anh"><img src="public/images/films/<?php if (!empty($mang[1])) echo $mang[1]; ?>"/></div>
                                    <div class="title"><?php if (!empty($mang[2])) echo $mang[2]; ?></div>
                                    <div class="mota"><?php if (!empty($mang[4])) echo $mang[4]; else echo "<span class='note'> No Dicrection</pan>"; ?></div>
                                    <div class="rating"><?php if (!empty($mang[3])) echo $mang[3]; ?></div>
                                    <div class="edit"><a href="edit.php?if=<?php echo $mang[0]; ?>">Edit</a></div>
                                </div>
                            <?php } ?>
                        <?php } else { ?>
                            <div class="item" <?php if(isset($_GET["id"])&&$_GET["id"]==$mang[0]) echo "id=edit"; ?>>
                                <div class="anh"><img src="public/images/films/<?php if (!empty($mang[1])) echo $mang[1]; ?>"/></div>
                                <div class="title"><?php if (!empty($mang[2])) echo $mang[2]; ?></div>
                                <div class="mota"><?php if (!empty($mang[4])) echo $mang[4]; else echo "<span class='note'> No Dicrection</pan>"; ?></div>
                                <div class="rating"><?php if (!empty($mang[3])) echo $mang[3]; ?></div>
                                <div class="edit"><a href="edit.php?if=<?php echo $mang[0]; ?>">Edit</a></div>
                            </div>
                        <?php } ?>
                    <?php } ?>
                <?php endforeach; ?>
            </div>
        </div>
    </div>

<?php } else { ?>
    <?php header("location:login.php"); ?>
<?php } ?>



